`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module: AUDIO_TOP                                                            //
// Author: Zhiyuan Lin                                                          //
// Date: 3/30/2014                                                              //
// Description: This module is the TOP module that combines everything.         //
// Signal: Sw1 & Sw2 are two switches for two different tunes.                  //
//         gain & shutdown are AMP's default I/O, here we configure them to 1   //
//         speaker is the output signal to drive the mono-speaker.              //
//////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
// NOTE: Synthesize pass, Implement Design pass.                                //
// Test: PASS, but need to modify the tunes and frequencies.                    //
//       3/31/2014                                                              //
//////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
// UPDATE: Add pause function 4/1/2014                                          //
//////////////////////////////////////////////////////////////////////////////////
module AUDIO_TOP(CLK, Sw1, Sw2, Btn_pause, gain, shutdown, speaker, seg_r);
    input CLK, Sw1, Sw2, Btn_pause;
	 output speaker;
	 output reg shutdown = 1;
	 output reg gain = 1;
	 output [7:0] seg_r;
	 wire [4:0] tone, tone1, tone2;
	 wire clk_div, tune1, tune2;
	 wire clk_4Hz1, clk_4Hz2, clk4Hz;

AUDIO_CLK_DIV M0 (clk_div, CLK, Btn_pause);
AUDIO_TUNE M21 (tune1, clk_div, clk_4Hz1, tone1);
AUDIO_TUNE2 M22 (tune2, clk_div, clk_4Hz2, tone2);
AUDIO_LED M3 (clk_4Hz, tone, seg_r);

assign speaker = (Sw1 == 1'b1)? tune1 :
                 (Sw2 == 1'b1)? tune2 : 1'b0;
					  
assign tone = (Sw1 == 1'b1)? tone1 :
              (Sw2 == 1'b1)? tone2 : 5'b0;
				
assign clk_4Hz = (Sw1 == 1'b1)? clk_4Hz1 :
                 (Sw2 == 1'b1)? clk_4Hz2 : 1'b0;
				   
endmodule
